package code.lewdy.db;

import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

public class DBConfigUtil
{

    private static Properties config;

    private static String url;

    private static String driver;

    private static String user;

    private static String password;

    private static boolean init = false;

    public static final String URL = "url";

    public static final String DRIVER = "driver";

    public static final String USER = "user";

    public static final String PASSWORD = "password";

    private static void init()
    {
        String propPath = "/db.properties";
        
        config = new Properties();
        InputStream in = DBConfigUtil.class.getResourceAsStream(propPath);
        try {
			config.load(in);
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
        init = true;
    }

    public static String getProperty(String key)
    {
        if (!init)
            init();
        return config.getProperty(key);
    }

    public static String getDriver()
    {
        return getProperty(DRIVER);
    }

    public static String getPassword()
    {
        return getProperty(PASSWORD);
    }

    public static String getUrl()
    {
        return getProperty(URL);
    }

    public static String getUser()
    {
        return getProperty(USER);
    }

    /**
     * @param args
     * @author liuding,2012-5-8
     */
    public static void main(String[] args)
    {
        // TODO Auto-generated method stub
         System.out.println(DBConfigUtil.getProperty(DBConfigUtil.URL));

    }

}
